package com.sayice.gomoku.filter;

import javax.servlet.*;
import java.io.IOException;

/**
 * 管理员登录检查
 */
public class AdminFilter implements Filter {
    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws ServletException, IOException {
        System.out.println("进入AdminFilter");
        Object admin = servletRequest.getAttribute("admin");
        if (admin == null) {
            servletRequest.getRequestDispatcher("/pages/admin/login.jsp").forward(servletRequest, servletResponse);
            System.out.println("转发至登录页面");
        } else {
            filterChain.doFilter(servletRequest, servletResponse);
        }
    }
}
